/*
 * testSound.c
 *
 *  Created on: 10-11-2013
 *      Author: Kuba
 */

#include "testSound.h"
/*****************************************************************************
 *
 * Description:
 *  Play sound sored in startupSound.c via speaker
 *
 ****************************************************************************/
void testSound(void){

	tU32 cnt = 0;
	tU32 i;

	if ((IOPIN & 1 << 14) == 0) {
		//Initialize DAC: AOUT = P0.25
		PINSEL1 &= ~0x000C0000;
		PINSEL1 |= 0x00080000;
		cnt = 0;

		while (cnt++ < 63137) {
			tS32 val;

			val = startupSound[cnt];
			DACR = ((val ) << 8) | (1 << 16);  //actual value to output
			//BIAS = 1, 2.5uS settling time
			//delay 125 us = 850 for 8kHz, 600 for 11 kHz
			for (i = 0; i < 850; i++)
				asm volatile (" nop");
		}
	}
}

